package com.eascs.notice.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.eascs.admin.o2o.loan.entity.O2oLoanapplyEntity;
import com.eascs.admin.o2o.loan.service.O2oLoanapplyService;
import com.eascs.common.util.StringUtil;
import com.eascs.common.util.UrlUtil;
import com.eascs.notice.entity.FormNoticeLetterEntity;
import com.eascs.notice.entity.O2oBankLoadDataEntity;
import com.eascs.notice.entity.O2oNoticeLetterFindEntity;
import com.eascs.notice.entity.OaBankLoadDataEntity;
import com.eascs.notice.entity.OaNoticeLetterFindEntity;
import com.eascs.notice.service.O2oNoticeLetterService;
import com.eascs.site.view.ViewContext;
import com.eascs.tag.MenuTag;

@Controller
@RequestMapping("/notice")
public class O2oNoticeLetterController extends NoticeBaseMasterController {

	@Autowired
	O2oLoanapplyService loanService;
	@Autowired
	O2oNoticeLetterService o2onoticeLetterservice;
	
	@Override
	public void preHandle() {
		super.preHandle();
		ViewContext.put(MenuTag.CURRENT_MENU_CODE, "loanManageNotice");
	}
	
	@RequestMapping("/basic")
	public String index(FormNoticeLetterEntity entity){
		StringBuffer o2oPageUrl = new StringBuffer("/rnotice/o2obasic");
		String o2oUrl = "";
		if (entity != null) {
			String billCode = entity.getBill_code() == null ? "" : entity.getBill_code();
			String userName = entity.getName() == null ? "" : entity.getName();
			String isUploadFile = entity.getIsUploadFile() == null ? "" : entity.getIsUploadFile();
			o2oUrl = UrlUtil.appendUrl(o2oPageUrl.toString(), "bill_code", billCode);
			o2oUrl = UrlUtil.appendUrl(o2oUrl, "name", userName);
			o2oUrl = UrlUtil.appendUrl(o2oUrl, "isUploadFile", isUploadFile);
		}
		o2oUrl = o2oUrl + "&showPage1=";
//		StringBuffer oaPageUrl = new StringBuffer("/rnotice/oabasic");
//		String oaUrl = "";
//		if (entity != null) {
//			String billCode = entity.getBill_code() == null ? "" : entity.getBill_code();
//			String userName = entity.getName() == null ? "" : entity.getName();
//			String isUploadFile = entity.getIsUploadFile() == null ? "" : entity.getIsUploadFile();
//			oaUrl = UrlUtil.appendUrl(oaPageUrl.toString(), "bill_code", billCode);
//			oaUrl = UrlUtil.appendUrl(oaUrl, "name", userName);
//			oaUrl = UrlUtil.appendUrl(oaUrl, "isUploadFile", isUploadFile);
//		}
//		oaUrl = oaUrl + "&showPage=";
		ViewContext.put("o2obasic", o2oUrl);
//		ViewContext.put("oabasic", oaUrl);
		ViewContext.put("vo", entity);
		return "/notice/letter";
	}

	@RequestMapping("/extend")
	public String getNoticeLetterData(String billCode) {
		O2oLoanapplyEntity loan = loanService.fingByBillCode(billCode);
		List<O2oNoticeLetterFindEntity> list = o2onoticeLetterservice.getNoticeLetterData(billCode);
		O2oBankLoadDataEntity bankLoadDataEntity = o2onoticeLetterservice.getLoanUserNameAndDate(billCode);
		String oafilePath = o2onoticeLetterservice.o2oFindUploadFilePath(billCode);
		if (!StringUtil.isEmpty(oafilePath)) {
			ViewContext.put("filePath", oafilePath);
		}
		ViewContext.put("nameTime", bankLoadDataEntity);
		ViewContext.put("noticeList", list);
		ViewContext.put("billCode", billCode);
		ViewContext.put("type", "");
		ViewContext.put("loan", loan);
		return "/notice/extend";
	}

	@RequestMapping("/oaextend")
	public String getOaNoticeLetterData(String billCode) {
		String bankLoanName = o2onoticeLetterservice.getBankLoanName(billCode);
		List<OaNoticeLetterFindEntity> list = o2onoticeLetterservice.getOaNoticeLetterData(billCode);
		OaBankLoadDataEntity bankLoadDataEntity = o2onoticeLetterservice.getOaLoanUserNameAndDate(billCode);
		String  oafilePath = o2onoticeLetterservice.oaFindUploadFilePath(billCode);
		if (!StringUtil.isEmpty(oafilePath)) {
			ViewContext.put("filePath", oafilePath);
		}
		ViewContext.put("nameTime", bankLoadDataEntity);
		ViewContext.put("noticeList", list);
		ViewContext.put("billCode", billCode);
		ViewContext.put("type", "old");
		ViewContext.put("bankLoanName", bankLoanName);
		return "/notice/extend";
	}
}